from tkinter import *  
  
win = Tk()  
win.title('键盘事件') 

def key_action(event):  
    print( "pressed", repr(event.char))
    s = event.char
    txt.set(s)
  
def callback(event):  
    L.focus_set()  

txt =  StringVar()
L = Label(win, width=20, textvariable = txt, font = 'song -36 bold',bg = 'cyan')
L.bind("<KeyPress>", key_action)
L.bind("<Button-1>", callback)
L.pack()   

win.mainloop()  
